package com.softline.documentsmall.controller;

import com.softline.documentsmall.entity.Handbook;
import com.softline.documentsmall.ret.BusinessErrorEnum;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.HandBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Author wph
 * @Date 2021/1/11 14:26
 */
@Api(value = "指南相关接口", tags = {"指南相关接口"})
@RestController
@RequestMapping("/handBook")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
public class HandBookController {
    @Autowired
    HandBookService Handbookservice;

    @ApiOperation(value = "根据页面类型,语法查询最后一次添加的单个页面类型(1探索数典,2编辑入门,3格式指南,4法律责任", notes = "根据页面类型查询最后一次添加的单个页面类型(1探索数典,2编辑入门,3格式指南,4法律责任")
    @GetMapping(value = "/query")
    public ReturnVO add(@RequestParam(name = "type", defaultValue = "en") String type, @RequestParam(name = "genre", defaultValue = "1") Long genre) {
        Handbook handbook = Handbookservice.query(type, genre);
        if (ObjectUtils.isEmpty(handbook)) {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        } else {
            return ReturnVOUtils.success(handbook);
        }
    }
}
